package logic

import (
	"context"
	"shopconnect/shoprpc/shoprpc"

	"shopconnect/api/internal/svc"
	"shopconnect/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopListLogic) ShopList(req *types.ShopListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.ShopRpc.ShopList(l.ctx, &shoprpc.ShopListRequest{
		Page: int64(req.Page),
		Size: int64(req.Size),
		Name: req.Name,
	})
	if err != nil {
		return &types.Response{
			Msg:  "展示失败" + err.Error(),
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "展示成功",
		Data: list,
		Code: 200,
	}, nil
}
